package com.wx.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.wx.dao.WxFansUserMapper;
import com.wx.dao.WxFansUserSQLMapper;
import com.wx.entity.WxFansUser;
import com.wx.entity.WxFansUserExample;
import com.wx.service.WxFansUserService;
@Service("wxFansUserServiceImpl")
public class WxFansUserServiceImpl implements WxFansUserService {
	@Resource
	private WxFansUserMapper fansusermapper;
	@Resource
	private  WxFansUserSQLMapper wxFansUserSQLMapper;
	@Override
	public int countByExample(WxFansUserExample example) {
		int countByExample = fansusermapper.countByExample(example);
		return countByExample;
	}

	@Override
	public int deleteByExample(WxFansUserExample example) {
		return fansusermapper.deleteByExample(example);
	}

	@Override
	public int deleteByPrimaryKey(Integer id) {
		return fansusermapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(WxFansUser record) {
		return fansusermapper.insert(record);
	}

	@Override
	public int insertSelective(WxFansUser record) {
		return fansusermapper.insertSelective(record);
	}

	@Override
	public List<WxFansUser> selectByExample(WxFansUserExample example) {
		return fansusermapper.selectByExample(example);
	}
	@Override
	public List<WxFansUser> selectByWxid(String wxid){
		WxFansUserExample example = new WxFansUserExample();
		example.createCriteria().andWxidEqualTo(wxid);
		return fansusermapper.selectByExample(example);
	}
	@Override
	public WxFansUser selectByPrimaryKey(Integer id) {
		return fansusermapper.selectByPrimaryKey(id);
	}

	@Override
	public List<WxFansUser> selectByNickName(String nickname) {
		WxFansUserExample example = new WxFansUserExample();
		example.createCriteria().andNicknameLike("%"+nickname+"%");
		List<WxFansUser> list = fansusermapper.selectByExample(example);	
		return list;
	}

	@Override
	public int updateByExampleSelective(WxFansUser record, WxFansUserExample example) {
		return fansusermapper.updateByExampleSelective(record, example)
				;
	}

	@Override
	public int updateByExample(WxFansUser record, WxFansUserExample example) {
		return fansusermapper.updateByExample(record, example);
	}

	@Override
	public int updateByPrimaryKeySelective(WxFansUser record) {
		return fansusermapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(WxFansUser record) {
		return fansusermapper.updateByPrimaryKey(record);
	}

	@Override
	public WxFansUser selectByOpenId(String openid) {
		WxFansUserExample example = new WxFansUserExample();
		example.createCriteria().andOpenidEqualTo(openid);
		PageHelper.startPage(1,1);
		List<WxFansUser> list = fansusermapper.selectByExample(example);
		if(list.size() == 1)
			return list.get(0);
		else
		return null;
	}

	@Override
	public List<WxFansUser> selectEntityByExample(Map<String, Object> params) {
		return this.fansusermapper.selectEntityByExample(params);
	}

	@Override
	public int countEntityByExample(Map<String, Object> params) {
		return this.fansusermapper.countEntityByExample(params);
	}

	@Override
	public List<String> selectAllOpenid(WxFansUserExample example) {
		return this.fansusermapper.selectAllOpenid(example);
	}

	@Override
	public WxFansUser selectByWxidAndOpenid(String wxid, String openid) {
		return this.fansusermapper.selectByWxidAndOpenid(wxid,openid);
	}

	@Override
	public List<WxFansUser> selectByWxidAndOpenid(String wxId, String... openid) {
		WxFansUserExample example = new WxFansUserExample();
		example.createCriteria().andWxidEqualTo(wxId).andOpenidIn(Arrays.asList(openid));
		List<WxFansUser> list =fansusermapper.selectByExample(example);
		if(list==null || list.isEmpty()){
			return null;
		}else{
			return list;
		}
	}
	
	@Override
	public WxFansUser selectByWxUserId(Long wxUserId) {
		return this.fansusermapper.selectByWxUserId(wxUserId);
	}

	@Override
	public List<WxFansUser> queryFansByTag(Map<String, Object> paramMap) {
		
		return wxFansUserSQLMapper.queryFansByTag(paramMap);
	}
	
}
